package com.mark.maven.ddd.app.impl;

import com.mark.maven.ddd.app.CreateOrderService;
import com.mark.maven.ddd.app.dto.req.CreateOrderRequest;
import com.mark.maven.ddd.app.dto.resp.BaseResponse;
import com.mark.maven.ddd.app.dto.resp.OrderInfo;
import com.mark.maven.ddd.app.translator.CreateOrderTranslator;
import com.mark.maven.ddd.domain.CreateOrderDomainRequest;
import com.mark.maven.ddd.domain.CreateOrderDomainResponse;
import com.mark.maven.ddd.domain.service.CreateOrderDomainService;
import org.springframework.stereotype.Service;

@Service
public class CreateOrderServiceImpl implements CreateOrderService {

    private final CreateOrderDomainService createOrderDomainService;
    private final CreateOrderTranslator createOrderTranslator;

    public CreateOrderServiceImpl(
            CreateOrderDomainService createOrderDomainService,
            CreateOrderTranslator createOrderTranslator) {
        this.createOrderDomainService = createOrderDomainService;
        this.createOrderTranslator = createOrderTranslator;
    }

    @Override
    public BaseResponse<OrderInfo> createOrder(CreateOrderRequest request) {
        CreateOrderDomainRequest domainRequest = createOrderTranslator.toDomainRequest(request);
        CreateOrderDomainResponse response = createOrderDomainService.createOrder(domainRequest);
        return BaseResponse.success(OrderInfo.builder().orderNo(response.getOrderNo()).build());
    }
}
